package xiaohuo.fancyring.listener

import eos.moe.dragoncore.api.event.EntityJoinWorldEvent
import ink.ptms.um.event.MobDeathEvent
import ink.ptms.um.event.MobSpawnEvent
import taboolib.common.platform.event.SubscribeEvent
import taboolib.common.platform.function.submit
import xiaohuo.fancyring.util.closeRing
import xiaohuo.fancyring.util.getRunningRealBody
import xiaohuo.fancyring.util.getShowRingData
import xiaohuo.fancyring.util.showRing

object Entities {
    @SubscribeEvent
    fun onRender(event: EntityJoinWorldEvent) {
        val uuid = event.entityUUID
        val player = event.player
        uuid.getShowRingData()?.showToPlayer(player)
        uuid.getRunningRealBody()?.showToPlayer(player)
    }

    @SubscribeEvent
    fun onSpawn(event: MobSpawnEvent) {
        event.mob?.entity?.let {
            submit(delay = 10) {
                it.showRing()
            }
        }
    }

    @SubscribeEvent
    fun onDeath(event: MobDeathEvent) {
        event.mob.entity.closeRing()
    }
}